package com.oop7.Company;

import java.util.Scanner;

public class Company {

	String companyName;
	String companyAddress;
	String companyPhone;
	String companyBusiness;
	Employee[] employee = new Employee[10];

	public String getCompanyName() {
		return companyName;
	}

	public void setCompanyName(String companyName) {
		this.companyName = companyName;
	}

	public String getCompanyAddress() {
		return companyAddress;
	}

	public void setCompanyAddress(String companyAddress) {
		this.companyAddress = companyAddress;
	}

	public String getCompanyPhone() {
		return companyPhone;
	}

	public void setCompanyPhone(String companyPhone) {
		this.companyPhone = companyPhone;
	}

	public String getCompanyBusiness() {
		return companyBusiness;
	}

	public void setCompanyBusiness(String companyBusiness) {
		this.companyBusiness = companyBusiness;
	}

	public boolean findEmployee(String employeeName) {// 寻找员工
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null && employeeName.equals(employee[i].getName())) {
				return true;
			}
		}
		return false;
	}

	public void offer(String employeeName, int age, String gender, String position, double salary) {// 招聘员工
		System.out.println("招聘员工");
		if (findEmployee(employeeName)) {
			System.out.println("员工姓名不能重复!");
			return;
		}
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] == null) {
				employee[i] = new Employee();
				employee[i].setName(employeeName);
				employee[i].setAge(age);
				employee[i].setGender(gender);
				employee[i].setPosition(position);
				employee[i].setSalary(salary);
				System.out.println("添加成功!");
				return;
			}
		}
		System.out.println("添加失败!");

	}

	public void showInfor() {// 显示员工信息
		System.out.println("员工信息：");
		System.out.println("序号\t姓名\t年龄\t性别\t职务\t薪水");
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null) {
				System.out.print((i + 1) + "、   ");
				employee[i].show();
			}
		}
	}

	public int findEmployeeNum(String name) {// 寻找员工编号
		int i, num = 0;
		for (i = 0; i < employee.length; i++) {
			if (employee[i] != null && name.equals(employee[i].getName())) {
				num = i;
			}
		}
		return num;
	}

	public void employeeNum() {// 统计公司人数
		System.out.println("统计公司人数");
		int num = 0;
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null) {
				num++;
			}
		}
		System.out.println("公司人数共有" + num + "人");

	}

	public void fire(String name) {// 开除员工
		employee[findEmployeeNum(name)] = null;
		System.out.println("已辞退员工" + name);
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] == null) {
				for (int j = i; j < employee.length; j++) {
					if (employee[j] != null) {
						employee[i] = employee[j];
						employee[j] = null;
						break;
					}
				}
			}
		}
	}

	public Employee findTopSalary() {
		int a = 0;
		for (int i = 0; i < employee.length; i++) {
			if (employee[i] != null) {
				if (i == 0) {
					a = i;
				} else {
					if (employee[i].getSalary() > employee[a].getSalary()) {
						a = i;

					}
				}
			}
		}
		return employee[a];
	}

	public Company() {

	}

	public Company(String companyName, String companyAddress, String companyPhone, String companyBusiness) {
		setCompanyName(companyName);
		setCompanyAddress(companyAddress);
		setCompanyPhone(companyPhone);
		setCompanyBusiness(companyBusiness);
	}

}
